package stream.test3;

//
//两个arraylist集合，分别储存男女演员的姓名和年龄，字符串中间用","隔开
//1、男演员三个字且前两个
//2、女演员姓杨且不是第一个
//3、过滤后的男女演员放一起
//4、将3的演员姓名封装成Actor对象
//5、将所有演员对象保存在list集合中
//

//"沙耶松,24","帕姆,23","涵江,22","张天舒,24","范中航,30","文轩清,27","李德全,25","王国栋,24","张立伟,22",
//"君安肆,27","小叶榕,30","杨颖,36","娜米玉,43","徐雅雯,31","许瑶,33","杨幂,33"

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Test3 {
    public static void main(String[] args) {
        //创建
        ArrayList<String> boyList = new ArrayList<>();
        ArrayList<String> girlList = new ArrayList<>();
        //添加
        Collections.addAll(boyList, "沙耶松,24","帕姆,23","涵江,22","张天舒,24",
                "范中航,30","文轩清,27","李德全,25","王国栋,24","张立伟,22");
        Collections.addAll(girlList,"君安肆,27","小叶榕,30","杨颖,36","娜米玉,43","徐雅雯,31","许瑶,33","杨幂,33");
        //过滤
        Stream<String> stream1 = boyList.stream()
                .filter(s -> s.split(",")[0].length() == 3)
                .limit(2);
        Stream<String> stream2 = girlList.stream()
                .filter(s -> s.split(",")[0].startsWith("杨"))
                .skip(1);
        //组合
        /*Stream.concat(stream1,stream2).map(new Function<String, Actor>() {
            @Override
            public Actor apply(String s) {
                String name = s.split(",")[0];
                int age = Integer.parseInt(s.split(",")[1]);
                return new Actor(name,age);
            }
        }).forEach(actor -> System.out.println(actor));*/

        List<Actor> list = Stream.concat(stream1, stream2)
                .map(s -> new Actor(s.split(",")[0], Integer.parseInt(s.split(",")[1])))
                .collect(Collectors.toList());
        System.out.println(list);
    }
}
